package com.kust.smarthome.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kust.smarthome.web.dto.OrderDto;
import com.kust.smarthome.web.dto.OrderDto2;
import com.kust.smarthome.web.model.OrderForm;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author iAuzre
 * @since 2021-07-09
 */
@Repository
public interface OrderFormMapper extends BaseMapper<OrderForm> {

    //查询所有订单
    @Select("select o.id as id," +
            "o.commodity_id as commodityId," +
            "o.address_id as addressId," +
            "o.courier_number as courierNumber," +
            "c.name as name," +
            "c.intro as intro," +
            "c.imgurl1 as imgurl1, " +
            "o.commodity_number as commodityNumber,"+
            "o.state as state," +
            "o.money as money," +
            "o.created as created " +
            "from order_form o " +
            "left join commodity c on c.id=o.commodity_id " +
            "where o.user_id=#{userId}")
    List<OrderDto> selectAll(Integer userId);

    //查询所有订单
    @Select("select o.id as id," +
            "o.commodity_id as commodityId," +
            "o.address_id as addressId," +
            "o.courier_number as courierNumber," +
            "o.commodity_number as commodityNumber,"+
            "o.state as state," +
            "o.money as money," +
            "o.created as created " +
            "from order_form o " +
            "left join commodity c on c.id=o.commodity_id " +
            "where o.user_id=#{userId}")
    List<OrderDto2> selectAll2(Integer userId);

    /*id commodityId addressId courierNumber money created*/
    @Select("select o.id as id," +
            "o.commodity_id as commodityId," +
            "o.address_id as addressId," +
            "o.courier_number as courierNumber," +
            "c.name as name," +
            "c.intro as intro," +
            "c.imgurl1 as imgurl1, " +
            "o.commodity_number as commodityNumber,"+
            "o.state as state," +
            "c.money as money," +
            "o.created as created " +
            "from order_form o " +
            "left join commodity c on c.id=o.commodity_id " +
            "where o.user_id=#{userId} and o.state=0")
    List<OrderDto> selectState0ByUserId(Integer userId);

    @Select("select o.id as id," +
            "o.commodity_id as commodityId," +
            "o.address_id as addressId," +
            "o.courier_number as courierNumber," +
            "c.name as name," +
            "c.intro as intro," +
            "c.imgurl1 as imgurl1, " +
            "o.commodity_number as commodityNumber,"+
            "o.state as state," +
            "c.money as money," +
            "o.created as created " +
            "from order_form o " +
            "left join commodity c on c.id=o.commodity_id " +
            "where o.user_id=#{userId} and o.state=1")
    List<OrderDto> selectState1ByUserId(Integer userId);

    @Select("select o.id as id," +
            "o.commodity_id as commodityId," +
            "o.address_id as addressId," +
            "o.courier_number as courierNumber," +
            "c.name as name," +
            "c.intro as intro," +
            "c.imgurl1 as imgurl1, " +
            "o.commodity_number as commodityNumber,"+
            "o.state as state," +
            "c.money as money," +
            "o.created as created " +
            "from order_form o " +
            "left join commodity c on c.id=o.commodity_id " +
            "where o.user_id=#{userId} and o.state=2")
    List<OrderDto> selectState2ByUserId(Integer userId);

    @Select("select o.id as id," +
            "o.commodity_id as commodityId," +
            "o.address_id as addressId," +
            "o.courier_number as courierNumber," +
            "c.name as name," +
            "c.intro as intro," +
            "c.imgurl1 as imgurl1, " +
            "o.commodity_number as commodityNumber,"+
            "o.state as state," +
            "c.money as money," +
            "o.created as created " +
            "from order_form o " +
            "left join commodity c on c.id=o.commodity_id " +
            "where o.user_id=#{userId} and o.state=3")
    List<OrderDto> selectState3ByUserId(Integer userId);

    @Select("select o.id as id," +
            "o.commodity_id as commodityId," +
            "o.address_id as addressId," +
            "o.courier_number as courierNumber," +
            "c.name as name," +
            "c.intro as intro," +
            "c.imgurl1 as imgurl1, " +
            "o.commodity_number as commodityNumber,"+
            "o.state as state," +
            "c.money as money," +
            "o.created as created " +
            "from order_form o " +
            "left join commodity c on c.id=o.commodity_id " +
            "where o.user_id=#{userId} and o.state=4")
    List<OrderDto> selectState4ByUserId(Integer userId);
}
